<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateSmsTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('sms', ['comment' => '短信验证码', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('event', 'string', ['limit'  =>  60, 'default' => '', 'comment' => '发送事件'])
            ->addColumn('mobile', 'string', ['limit'  =>  20, 'default' => '', 'comment' => '手机号'])
            ->addColumn('code', 'string', ['limit'  =>  10, 'default' => '', 'comment' => '验证码'])
            ->addColumn('times', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '验证次数'])
            ->addColumn('ip', 'string', ['limit'  =>  20, 'null' => true, 'default' => null, 'comment' => 'ip'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('event')
            ->addIndex('mobile')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('sms');
        $table->drop();
    }
}
